home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / ANIVGA.ARJ / EXAMPLE4.PAS < prev    next >
Pascal/Delphi Source File  |  1991-11-10  |  2KB  |  57 lines

  1. PROGRAM Example4;
  2.  
  3. {Demonstrates use of sprite cycles & SetCycleTime() to control animation speed}
  4.  
  5. USES ANIVGA,CRT;
  6. CONST LoadHantel=1;
  7.       SpriteName='HANTEL.LIB'; {Path and name of the sprite to load}
  8.       flip:BOOLEAN=FALSE;      {Flag for animation speed}
  9. VAR ch:CHAR;
  10.     PicsLoaded:BYTE;
  11.     i,n:WORD;
  12.  
  13. BEGIN
  14.  PicsLoaded:=loadSprite(SpriteName,LoadHantel); {load sprites}
  15.  IF Error<>Err_None
  16.   THEN BEGIN
  17.         CloseRoutines;
  18.         WRITELN('Error: '+GetErrorMessage); halt(1)
  19.        END;
  20.  SetSpriteCycle(LoadHantel,PicsLoaded); {cycle through all images endlessly}
  21.  
  22.  InitGraph;
  23.  
  24.  FillBackground(76);
  25.  
  26.  FOR i:=1 TO 100 DO  {choose app. 100 sprites}
  27.   BEGIN
  28.    n:=RANDOM(NMAX)+1;
  29.    SpriteN[n]:=LoadHantel+RANDOM(PicsLoaded);  {enter cycle somewhere}
  30.    SpriteX[n]:=RANDOM(XMAX+1);  {use a random coordinates}
  31.    SpriteY[n]:=RANDOM(YMAX+1)
  32.   END;
  33.  
  34.  ch:=#0; {clear input}
  35.  REPEAT
  36.   IF KeyPressed
  37.    THEN BEGIN
  38.          ch:=UpCase(ReadKey);
  39.          CASE ch OF
  40.           'E':dec(StartVirtualY,10);  {change position of whole scene with}
  41.           'S':dec(StartVirtualX,10);  {E,S,D,X}
  42.           'D':inc(StartVirtualX,10);
  43.           'X':inc(StartVirtualY,10);
  44.           ' ':BEGIN   {toggle speed between maximum and 200ms per frame}
  45.                flip:=NOT flip;
  46.                IF flip
  47.                 THEN SetCycleTime(200)
  48.                 ELSE SetCycleTime(0)
  49.               END;
  50.          END;
  51.         END;
  52.   Animate;
  53.  UNTIL ch='Q';
  54.  
  55.  CloseRoutines;
  56. END.
  57.